
import "./details.scss"
import $ from "jquery";
import ProfileMgr from "../../libs/ProfileMgr.js";
import BuyCar from "../../parts/inc/header.js"

//购物车
;
class Details{
    constructor(){
        this.init.call(this);
    }   
    //初始化
    init(){
        this.m_count = 1;
        ProfileMgr.repeatLoad(); 
        this.bindEvent();
    }
    //事件绑定
    bindEvent(){
        let that =  this;
        $(".option_c li").mouseenter(function () {
            //获取点击的元素给其添加样式，讲其兄弟元素的样式移除
            $(this).addClass("border_r").siblings().removeClass("border_r");
            //获取选中元素的下标
            var index = $(this).index();
            $(".photo_big li").css({
                display: function () {
                    if (index == $(this).index()) {
                        return "block"
                    } else {
                        return "none"
                    }
                }
            });
        });

        $(".num_value").on("click", ".num_l",function(){
            that.removeGoods();
        });
        $(".num_value").on("click", ".num_r",function(){
            that.addGoods();
        });
        $(".num_value").on("blur", ".text",function(){
            that.changeGoodsCount();
        });
        $(".addcar").click(function(){
            that.addToShopCart();
        });
    }
    // 增加一件
    addGoods(){
        this.m_count ++;
        $(".text").val(this.m_count);
    }
    // 减少一件
    removeGoods(){
        this.m_count --;
        if(this.m_count <= 1){
            this.m_count = 1;
        }
        $(".text").val(this.m_count);
    }
    //手动改变数量
    changeGoodsCount(){
        let value = parseInt($(".text").val());
        if(value >= 1){
        }
        else{
            value = 1;
        }
        this.m_count = value;
    }
    //向购物车添加商品
    addToShopCart(){
        ProfileMgr.addCartListById(113,this.m_count);
        // 同步购物车商品数量
        let totalCount = ProfileMgr.getCartCount();
        $(".ling").html(totalCount);

        // 右边购物车显示
        // if(typeof this.m_callback == "function") this.m_callback();
    }
}

$(function () {
    new Details()
});
$(function(){
    $('#top').load('./header.html',function(){
        new BuyCar();
    });
    $('#footer').load('./footer.html');

   
    
})